/**
 * 
 */
package comparison.sort.algorithm;

/**
 * @author xuanh_000
 *
 */
public class QuickSort extends Sort{
	private SequenceNumText sequenceNumText = new SequenceNumText();
	private int countSwap=1;
	public QuickSort(int max){
		super(max);
	}
	public QuickSort(long[] data){
		super(data);
	}
	public void run( int left, int right) {
		if (left >= right)
			return;
		logSort += "\n"+sequenceNumText.getNumText(countSwap++);
		String lineLogTemp=stringData();
		int k=(left+right)/2;
		long temp=data[k];
		swap(k,right);
		int i=left, j=right-1;
		while(i<=j){
			while (i<=right && data[i]<=temp)
				i++;
			while (j>=left && data[j]>temp)
				j--;
			String logSwap="";
			if(i<=j){
				logSwap = " Swap since "+i+"<="+j;
				swap(i,j);
			}
			lineLogTemp+=stringData()+logSwap+"\n";
			logSort +=lineLogTemp;
		}
		swap(j+1,right);
		run( left, j);
		run( j+2, right);
	}
}
